package org.example.pojo;


//统一响应结果

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.utils.KuaiZuConst;

@NoArgsConstructor//无参构造
@AllArgsConstructor//有参构造
@Data//添加getset方法
public class Result<T> {
    private Integer code;//业务状态码  0-成功  1-失败
    private String message;//提示信息
    private T data;//响应数据

    //快速返回操作成功响应结果(带响应数据)
    public static <E> Result<E> success(E data) {
        return new Result<>(KuaiZuConst.RETURN_SUCCESS_CODE, "操作成功", data);
    }

    //快速返回操作成功响应结果
    public static Result success() {
        return success(KuaiZuConst.RETURN_SUCCESS_CODE,"操作成功",null);
    }
    public static Result success(String message) {
        return success(KuaiZuConst.RETURN_SUCCESS_CODE,message,null);
    }
    public static Result success(String message, Object date) {
        return success(KuaiZuConst.RETURN_SUCCESS_CODE,message,date);
    }
    public static Result success(Integer code,String message, Object date) {
        return new Result(code, message, date);
    }

    public static Result error(String message) {
        return error(KuaiZuConst.RETURN_ERROR_CODE,message,null);
    }
    public static Result error(String message,Object date) {
        return error(KuaiZuConst.RETURN_ERROR_CODE,message,date);
    }

    public static Result error(Integer code,String message, Object date) {
        return new Result(code, message, date);
    }
}
